{extend name="base"/}
{block name="resources"}
<style>
	.ns-form {margin-top: 0;}
</style>
{/block}
{block name="main"}
<div class="layui-form ns-form">
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>等级名称：</label>
		<div class="layui-input-block">
			<input name="level_name" type="text" lay-verify="required" class="layui-input ns-len-long" value="{$level_info.data.level_name}">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">权益描述：</label>
		<div class="layui-input-block ns-len-long">
			<textarea name="remark" class="layui-textarea">{$level_info.data.remark}</textarea>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">成长值：</label>
		<div class="layui-input-block">
			<input name="growth" type="number" class="layui-input ns-len-short" lay-verify="num" value="{$level_info.data.growth}">
		</div>
		<div class="ns-word-aux">修改等级所需成长值后，部分客户会因无法达到该成长值要求而发生会员等级的变化</div>
	</div>
	
	<!-- <div class="layui-form-item">
		<label class="layui-form-label">是否默认：</label>
		<div class="layui-input-block">
			<input type="checkbox" name="is_default" value="1" lay-skin="switch" {if $level_info.data.is_default==1}checked{/if} />
		</div>
	</div> -->

	<div class="ns-form-row">
		<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
		<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
	</div>
	
	<!-- 隐藏域 -->
	<input id="levelId" type="hidden" name="level_id" value="{$level_info.data.level_id}" />
</div>

{/block}
{block name="script"}
<script>
	layui.use('form', function() {
		var form = layui.form,
			repeat_flag = false; //防重复标识
		form.render();

		/**
		 * 监听保存
		 */
		form.on('submit(save)', function(data) {
			
			if(repeat_flag) return false;
			repeat_flag = true;
			
			$.ajax({
				url: ns.url("admin/memberlevel/editLevel"),
				data: data.field,
				type: "POST",
				dataType: "JSON",
				success: function(res) {
					repeat_flag = false;
					if (res.code == 0) {
						layer.confirm('编辑成功', {
							title:'操作提示',
							btn: ['返回列表', '继续操作'],
							yes: function(){
								location.href = ns.url("admin/memberlevel/levelList")
							},
							btn2: function() {
								location.reload();
							}
						});
					}else{
						layer.msg(res.message);
					}
				}
			});
		});
		
		/**
		 * 表单验证
		 */
		form.verify({
			num: function(value) {
				var arrMen = value.split(".");
				var val = 0;
				if (arrMen.length == 2) {
					val = arrMen[1];
				}
				
				if (value == "") {
					return false;
				}
				if (value < 0 || val.length > 2) {
					return '请输入大于0的数，保留小数点后两位'
				}
			}
		});
	});
	
	function back(){
		location.href = ns.url("admin/memberlevel/levelList");
	}
</script>
{/block}